package com.rp.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.rp.common.utils.RpUtil;

public class HtmlEncodeTag extends TagSupport {

	private static final long serialVersionUID = -6600637487757970020L;
	
	private String source = "";

	@Override
	public int doEndTag() throws JspException {
		
		JspWriter out = pageContext.getOut();
		try{
			if(RpUtil.isNullOrEmpty(source)){
				out.print("<span style='color: red;'>No Content!（无内容）</span>");
			}else{
				//out.print(ESAPI.encoder().encodeForHTML(source));
				if(!RpUtil.isNullOrEmpty(id)){
					out.print("<span id='"+id+"'>"+RpUtil.htmlEncode(source)+"</span>");
				}else{
					out.print(RpUtil.htmlEncode(source));
				}
			}
		}catch (IOException e) {
			throw new JspException(e);
		}
		
		return EVAL_PAGE;
	}
	
	
	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}
	
}
